/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asja.formulario;

import asja.dao.ExemploDao;
import asja.modelo.ExemploModelo;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import javax.swing.*;


/**
 *
 * @author Alice
 */
public class ExemploFormulario extends JFrame {
    
    private JTextField jtf_nome= new JTextField("", 10);
    private JLabel lbl_nome = new JLabel("Nome: ");
    private JButton bt_ok= new JButton("OK");
    private JButton bt_cancelar= new JButton("Cancelar");
    
    public ExemploFormulario(){
        
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        this.setTitle("Exemplo");  
        this.setSize(400, 200);          
        this.setLocationRelativeTo(null); 
        this.setVisible(true);
        
    }
    
     // criando a janela
    public void criaJanela()  
    {  
    
        JPanel painel_geral = new JPanel();
        painel_geral.setLayout(new FlowLayout());        
        painel_geral.add(lbl_nome);
        painel_geral.add(jtf_nome);
        painel_geral.add(bt_cancelar);
        painel_geral.add(bt_ok);
        this.getContentPane().add(painel_geral);
        
        
        //Classe interna para o evento do Botão Cancelar
         bt_ok.addMouseListener(new MouseAdapter() {
       // @Override
            public void mouseClicked(MouseEvent evt) {
              cadastro_login();
      
        }});
        
        pack();    
    
    
    }
    
    
    public void cadastro_login(){   

         try {
             ExemploModelo in = new ExemploModelo();
             in.setNome(jtf_nome.getText());
             ExemploDao contr = new ExemploDao();
             contr.adiciona(in);            
          } catch (SQLException ex) {
             System.out.println("Erro!!");

         }   
     
    }
    

     public static void main(String[] args){
         
         ExemploFormulario ex= new ExemploFormulario();
         ex.criaJanela();
         
     }
    
     
 
}
